import { _decorator, Component, Node } from 'cc';
import { BaseManager } from '../../libs/rxjs/cc3/BaseManager';
import { color } from 'cc';
import { director } from 'cc';
import { System } from 'cc';
import { sys } from 'cc';
import { jsb_sdk_m } from './JsbSDKManager';
const { ccclass, property } = _decorator;

@ccclass('NotificationCocosSDKManager')
export class NotificationCocosSDKManager extends BaseManager {

    public static instance: NotificationCocosSDKManager;
    static ID = 'notification_sdk_system';
    get logColorOverride() { return color().fromHEX('#EECCDD') };

    static registerSystem() {
        director.unregisterSystem(director.getSystem(NotificationCocosSDKManager.ID));
        director.registerSystem(NotificationCocosSDKManager.ID, notification_sdk_m, System.Priority.MEDIUM);
        notification_sdk_m.init();
    }

    onInitManager() {
        this.log('onInitManager', this.timestamp);
        if (sys.isNative) {
        }
    }

    requestPermission() {
        if (!sys.isNative) return;
        jsb_sdk_m.sendMsg('NotificationCocosSDK.requestPermission', '{}');
    }

    requestScheduleNotification(identifier: string, title: string, body: string, date: Date) {
        if (!sys.isNative) return;
        let obj = { identifier, title, body, date: date.valueOf() };
        jsb_sdk_m.sendMsg('NotificationCocosSDK.requestScheduleNotification', JSON.stringify(obj));
    }

    requestRemoveNotification(identifier: string) {
        if (!sys.isNative) return;
        let obj = { identifier };
        jsb_sdk_m.sendMsg('NotificationCocosSDK.requestRemoveNotification', JSON.stringify(obj));
    }

}

globalThis.NotificationCocosSDKManager = NotificationCocosSDKManager;

export const notification_sdk_m = NotificationCocosSDKManager.instance = new NotificationCocosSDKManager();